package VNF_DelayTest_large_modified01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.net2plan.interfaces.networkDesign.Node;

public class Temp {
	
//	//每组仿真前，先对网络拓扑进行初始化
//	if(k%numberOfRequests==0) {
//		InitialNetPlan.initialNetplan();
//	}
//	String ch = new String() ;
//	ch = "/Users/shentianyu/Net2Plan-0.4.0/workspace/data/networkTopologies/US_Backbone.n2p";
//	File f1 = new File(ch);
//	NetPlan netplan = new NetPlan(f1);
//	List<Node> subNodes = new ArrayList<Node>();
//	System.out.println("start "+(k+1));
//	NetPlan request = requestList.get(k);
//	requestGroup.add(request);
//	List<Link> requestLinks = request.getLinks(request.getNetworkLayerDefault());
//	NodeMappingReturn nodeMappingReturn = new NodeMappingReturn();
//	LinkMappingReturn linkMappingReturn = new LinkMappingReturn();
//	nodeMappingReturn = MyUtil.nodeMapping(netplan, request);
//	if(nodeMappingReturn.isSign()) {
//		linkMappingReturn = MyUtil.linkMapping(netplan, request);
//		if(linkMappingReturn.isSign()) {
//			System.out.println("this request has been successfully served!");
//		}
//		else{
//			System.out.println("linkmapping failed!");
//		}
//	}
//	else {
//		System.out.println("nodemapping failed!");
//	}
//	for(Link link:requestLinks) {
//		System.out.print(link.getAttribute("pathlength"));
//		System.out.println();
//	}
//	File f_1 = new File(ch);
//	netplan.saveToFile(f_1);
//	subNodes = netplan.getNodes();
//	if(k%numberOfRequests==numberOfRequests-1) {
//		//读数据,set DelayTime属性
//		for(NetPlan thisRequest: requestGroup) {
//			double delayTime = 0.0;
//			for(Node node:thisRequest.getNodes()) {
//				String vnfType = node.getAttribute("VNF");
//				if(!"0".equals(vnfType)) {
//					int subIndex = Integer.valueOf(node.getAttribute("MappedNode")).intValue();
//					Node subNode = subNodes.get(subIndex);
//					int numberOfThisVNF = Integer.valueOf(subNode.getAttribute(vnfType)).intValue();
//					int vnf = Integer.valueOf(vnfType).intValue();
//					delayTime+=(vnf+1)*5*numberOfThisVNF;
//				}
//			}
//			double pathLength = 0.0;
//			for(Link link:thisRequest.getLinks(thisRequest.getNetworkLayerDefault())) {
//				pathLength+=Double.valueOf(link.getAttribute("pathlength")).doubleValue();
//			}
//			delayTime+=pathLength/200.0;
//			thisRequest.setAttribute("DelayTime",String.valueOf(delayTime) );
//		}
//		double totalDelayTime = 0.0;
//		double totalThreadTime = 0.0;
//		int blockNumber = 0;
//		for(NetPlan thisRequest: requestGroup) {
//			double dt = Double.valueOf(thisRequest.getAttribute("DelayTime")).doubleValue();
//			double tt = Double.valueOf(thisRequest.getAttribute("ThreadTime")).doubleValue();
//			if(dt>tt) {
//				blockNumber++;
//			}
//			totalDelayTime+=Double.valueOf(thisRequest.getAttribute("DelayTime")).doubleValue();
//			totalThreadTime+=Double.valueOf(thisRequest.getAttribute("ThreadTime")).doubleValue();
//		}
//		double block = (blockNumber*1.0)/(numberOfRequests*1.0);
//		netplan.setAttribute("block", String.valueOf(block));
//		netplan.setAttribute("TotalDelayTime", String.valueOf(totalDelayTime));
//		netplan.setAttribute("TotalThreadTime", String.valueOf(totalThreadTime));
//		requestGroup.clear();
//		blockList.add(block);
//		totalDelayTimeList.add(totalDelayTime);
//		int mfsi = MyUtil.MFSI(netplan);
//		netplan.setAttribute("MFSI", String.valueOf(mfsi));
//		mfsiList.add(mfsi);
//		int totalusedcpu = 0;
//		for(Node node:subNodes) {
//			if("1".equals(node.getAttribute("DataCenter"))) {
//				System.out.println(" 数据中心"+subNodes.indexOf(node));
//				for(int vnfType = 1;vnfType<=numberOfAllVNFTypes;vnfType++) {
//					System.out.print(" VNF"+vnfType+": "+node.getAttribute(String.valueOf(vnfType))+",  ");
//					int vnfNum = Integer.valueOf(node.getAttribute(String.valueOf(vnfType))).intValue();
//					if(vnfNum>0) {
//						totalusedcpu+=vnfType;
//					}
//				}
//				System.out.println();
//			}
//		}
//		totalUsedCPUList.add(totalusedcpu);
//		netplan.setAttribute("TotalUsedCPU", String.valueOf(totalusedcpu));
//		double averageCost =  totalDelayTime/totalThreadTime+(totalusedcpu*1.0)/(numberOfCPU*numberOfDC*1.0)+(mfsi*1.0)/(numberOfAllSlot*1.0);
//		averageCostList.add(averageCost);
//		netplan.setAttribute("AverageCost", String.valueOf(averageCost));
//		
//		System.out.println("TotalUsedCPU: "+netplan.getAttribute("TotalUsedCPU"));
//		System.out.println("TotalDelayTime: "+netplan.getAttribute("TotalDelayTime"));
//		System.out.println("TotalThreadTime: "+netplan.getAttribute("TotalThreadTime"));
//		System.out.println("MFSI: "+netplan.getAttribute("MFSI"));
//		System.out.println("block"+netplan.getAttribute("block"));
//		System.out.println("AverageCost: "+netplan.getAttribute("AverageCost"));
//	}
//	if(k==numberOfAllRequests-1) {
//		System.out.println("------------------------------------------------");
//		System.out.print("TotalUsedCPU: ");
//		for(Integer i:totalUsedCPUList) {
//			System.out.print(i.intValue()+"  ");
//		}
//		System.out.println();
//		
//		System.out.print("MFSI: ");
//		for(Integer i:mfsiList) {
//			System.out.print(i.intValue()+"  ");
//		}
//		System.out.println();
//		
//		System.out.print("TotaoDelayTime: ");
//		for(Double d:totalDelayTimeList) {
//			System.out.print(String.format("%.6f", d.doubleValue())+"  ");
//		}
//		System.out.println();
//		
//		System.out.print("block: ");
//		for(Double d:blockList) {
//			System.out.print(String.format("%.6f", d.doubleValue())+"  ");
//		}
//		System.out.println();
//		System.out.println();
//		
//		System.out.print("AverageCost: ");
//		for(Double d:averageCostList) {
//			System.out.print(String.format("%.6f", d.doubleValue())+"  ");
//		}
//		System.out.println();
//		System.out.println();
//		
//		System.out.println("TotalUsedCPU avg: "+MyUtil.getAvgvalue(totalUsedCPUList));
//		System.out.println("MFSI avg: "+MyUtil.getAvgvalue(mfsiList));
//		System.out.println("TotalDelayTime avg: "+String.format("%.6f", MyUtil.getDoubleAvgvalue(totalDelayTimeList)));
//		System.out.println("block avg: "+String.format("%.6f", MyUtil.getDoubleAvgvalue(blockList)));
//		System.out.println("AverageCost avg: "+String.format("%.6f", MyUtil.getDoubleAvgvalue(averageCostList)));
//	}
	public static void main(String[] args) {
		List<Integer> list = new ArrayList<Integer>();
		Integer a = 0;
		Integer b = 1;
		Integer c = 2;
		list.add(a);
		list.add(b);
		list.add(c);
		Temp.moveToEnd(0, list);
		for(Integer i : list) {
			System.out.println(i.intValue());
		}
	}
	public static void moveToEnd(int index,List<Integer>nodeList) {
		for(int i=index;i<nodeList.size()-1;i++) {
			Collections.swap(nodeList, i, i+1);
		}
	}

}
